package day6;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo5Animal {
    //名称
    private String name;
    //年龄
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
//继承自动物类
class Cat extends Demo5Animal{
    public void voice(){
        System.out.println("voice");
    }
    public void eat(){
        System.out.println("eat");
    }
    public void save(ArrayList<Demo5Animal> list){
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 2; i++) {
            Demo5Animal demo5Animal = new Demo5Animal();
            System.out.println("输入名称:");
            demo5Animal.setName(sc.next());
            System.out.println("输入年龄:");
            demo5Animal.setAge(sc.nextInt());
            list.add(demo5Animal);
        }
    }
    public void show(ArrayList<Demo5Animal> list){
        for (int i = 0; i < list.size(); i++) {
            System.out.println("名称:"+list.get(i).getName()+",年龄:"+list.get(i).getAge());
        }
    }
}
class Dog extends Demo5Animal{
    public void voice(){
        System.out.println("voice");
    }
    public void eat(){
        System.out.println("eat");
    }
}